<!-- 基本信息 -->

<template>
  <div>
    <MajorTitle title="基本信息" />

    <EasyRow col2>
      <FormInput label="规则名称" bind="name" :max="20" required />
      <FormStatus isRadio />
    </EasyRow>

    <EasyRow col2>
      <FormSelect
        label="设备类别"
        bind="deviceCategory, deviceCategoryName, deviceCategoryId"
        :dict="categoryDict"
        required
      />
      <FormSelect label="设备类型" bind="deviceType, deviceTypeName, deviceTypeId" :dict="typeDict" required />
    </EasyRow>

    <FormRadio label="作用范围" bind="deviceMatch" :dict="DICT.MATCH" :disabled="!one.deviceType" required />

    <BaseDevice />
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyBase',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 设备类别字典
     */
    categoryDict() {
      return this.$root.iot_category_selectDict.map(([id, name, code]) => [code, name, id])
    },

    /**
     * 设备类型字典
     */
    typeDict() {
      const { one, $root: { iot_type_selectDict: typeDict } } = this
      return typeDict.filter((dict) => dict[3] === one.deviceCategory).map(([id, name, code]) => [code, name, id])
    },
  },

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听设备类型
     */
    'one.deviceType'() {
      this.one.deviceMatch = undefined
    },
  },
}
</script>
